#include "StdAfx.h"
#include "TimeDebuger.h"
#include "Font.h"
#include "game.h"

int TimeDebuger::m_diff = 0;
TimeDebuger::TimeDebuger(void)
{
	m_nbTimer = 0;
}

TimeDebuger::~TimeDebuger(void)
{
	
}

void TimeDebuger::StartFrame()
{
	m_nbTimer = 0;
	TimeCheck("Start");	
}

void TimeDebuger::TimeCheck(char* str)
{
	ASSERT(strlen(str) <8);

	strcpy(m_strs[m_nbTimer],str);	 
	m_t[m_nbTimer++] = S_GetTime();
}

void TimeDebuger::ShowLog()
{
	if(m_nbTimer<=1)
		return;

	Font* fm = getFont();
	if(fm == NULL)
		return;

	m_t[m_nbTimer++] = S_GetTime();
	
	float x =3;
	float y = 5;
	char strInfo[64];
	u32 totalTIme = 0;
	for(int i =0;i<m_nbTimer-1;i++)
	{
		
		totalTIme += (m_t[i+1]-m_t[i]);
		sprintf(strInfo, "%s:%d",m_strs[i], m_t[i+1]-m_t[i]);

		fm->DrawText2((GL_TCHAR*)strInfo, x, y);

		y-=0.3f;
		if(y < 0)
		{
			y = 5;
			x += 1;
		}
	}

	sprintf(strInfo, "Total:%d",totalTIme);
	fm->DrawText2((GL_TCHAR*)strInfo, x, y);

	sprintf(strInfo, "Diff:%d",m_diff);
	fm->DrawText2((GL_TCHAR*)strInfo, 1, 1);
	
	
}